package online.shiming.file.util;
import com.aliyun.oss.model.OSSObjectSummary;
import com.aliyun.oss.model.Owner;

import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * @author ShiMing
 * @version 1.0
 * @name OSSDo
 * @description TODO 文件数据
 * @date 2020/11/16
 */

@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class OSSDo {
    private String bucketName;
    private String key;
    private String eTag;
    private long size;
    private Date lastModified;
    private String storageClass;
    private Owner owner;
    private String type;
    private String id;
    private String parentId;
    private String name;

    public static HashSet<String> year = new HashSet<>();
    public static HashSet<String> month = new HashSet<>();
    public static HashSet<String> day = new HashSet<>();
    public static HashMap<String, Object> dateData = new HashMap<>();

    public void setDate() {
        String[] date = key.split("/");
        year.add(date[0]);
        month.add(date[0] + "/" + date[1]);
        day.add(date[0] + "/" + date[1] + "/" + date[2]);

        this.setId(date[0] + date[1] + date[2] + date[3]);
        this.setName(date[3]);
        this.setParentId(date[0] + date[1] + date[2]);

        this.setDateData(date[0]);
        this.setDateData(date[0] + date[1]);
        this.setDateData(date[0] + date[1] + date[2]);

    }

    public void setDateData(String type) {

        Long allSize = (Long) dateData.get(type+"size");
        Date allLastModified = (Date) dateData.get(type+"lastModified");
        dateData.put(type + "size", allSize == null ? this.size : allSize + this.size);
        if (allLastModified == null) {
            dateData.put(type + "lastModified", lastModified);
        } else {
            dateData.put(type + "lastModified", allLastModified.compareTo(lastModified) > 0 ?
                    allLastModified : this.lastModified);
        }
    }

}
